/*
 Copyright (C) 2010-2013. 
 Ezequiel Palumbo, Calipsoide FOSS Foundation.
 
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU Lesser General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU Lesser General Public License for more details.

 You should have received a copy of the GNU Lesser General Public License
 along with this program.  If not, see http://www.gnu.org/licenses/. 
 
 Email: contacto@ehpalumbo.com.ar 
*/

package org.calipsoide.dbf2xml.model;

/**
 * 
 * Representation of a record field. Has name and generic value. 
 * 
 * @since 1.0
 * @author ehpalumbo
 *
 */
public class Field {

	private final String name;
	private Object value;

	/**
	 * 
	 * Creates a field, only with its name. Value is unspecified.
	 * 
	 * @param name of the field
	 * 
	 */
	public Field(String name) {
		this(name, null);
	}

	/**
	 * 
	 * Creates a field with name and value.
	 * 
	 * @param name of the field
	 * @param value of the field in the record
	 * 
	 */
	public Field(String name, Object value) {
		super();
		this.name = name;
		this.value = value;
	}

	public String getName() {
		return name;
	}

	public Object getValue() {
		return value;
	}

	public void setValue(Object value) {
		this.value = value;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result + ((value == null) ? 0 : 
				value.toString().trim().hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Field other = (Field) obj;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (value == null) {
			if (other.value != null)
				return false;
		} else if (!value.toString().trim().equals(
				other.value.toString().trim()))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return name + " = '" + value + "'";
	}

}
